package com.richardjaap.data;

import javax.xml.bind.annotation.XmlElement;

public class Player {
	
	private int id;
	private double cashBuyIn;
	private int currentTable;
	
	public Player(Account account){
		this.id = account.getId();
	}
	
	public int joinTable(int tableId, double cash){
		Account a = Lobby.getInstance().getAccount(id);
		if(a.getCashTotal() != 0){
			currentTable = tableId;
			RouletteTable t = Lobby.getInstance().getTable(tableId);
			if(a.getCashTotal() >= cash){
				setCashBuyIn(cash);
				a.setCashTotal(a.getCashTotal() - cash);
				t.addPlayer(this);
				return 1;
			} else {
				return -1;
			}
		} else
			System.out.println("Your balance is 0. You should top up first.");
		return -2;
	}

	public boolean bet(Bet bet){
		if(bet.getAmount() > cashBuyIn)
			return false;
		cashBuyIn -= bet.getAmount();
		System.out.println(cashBuyIn);
	    Lobby.getInstance().getTable(currentTable).placeBet(bet);
		return true;
	}
	
	public RouletteTable gedCurrentTable()
	{
		return Lobby.getInstance().getTable(currentTable);
	}

	public int getId() {
		return id;
	}
	
	public double getCashBuyIn() {
		return cashBuyIn;
	}

	public void setCashBuyIn(double cashBuyIn) {
		this.cashBuyIn = cashBuyIn;
	}
	
	public void addCash(double cash)
	{
		cashBuyIn += cash;
	}
	
	public String toString(){
		return "ID: " + id + " Cash: " + cashBuyIn;
	}
}
